<?php

namespace app\store\controller\setting;

use app\store\controller\BaseController;
use app\store\service\PaymentConfigService;
use think\exception\ValidateException;
use think\facade\View;

class PaymentController extends BaseController
{
    public function index()
    {

        $row = PaymentConfigService::findPaymentConfig();

        return View::fetch('',['row' => $row]);
    }

    public function save()
    {
        $param = $this->request->post();

        try{
            validate('PaymentConfigValidate')->check($param);
        }catch (ValidateException $e){
            return json(['code' => 0, 'msg' => $e->getMessage()]);
        }


        $id =  PaymentConfigService::savePaymentConfig($param);

        return $id ? json(['code' => 1, 'msg' => '保存成功!']) : json(['code' => 0, 'msg' => '保存失败!']);

    }

}